﻿using MediatR;
using ProduceBasicData.Api.Application.Command.ProductionManage.Technology;
using ProduceBasicData.Domain.WarehouseManage;
using ProduceBasicData.ErrorCode;
using ProduceBasicData.Infrastructure.Interface;

namespace ProduceBasicData.Api.Application.Handler.ProductionManage.Technology
{
    /// <summary>
    /// 仓库库区库位下拉框
    /// </summary>
    public class GetStorageLocationCommandHandler : IRequestHandler<GetStorageLocationCommand, ApiResult<List<StorageLocation>>>
    {
        private readonly IBaseRespository<StorageLocation> _storageLocation;

        public GetStorageLocationCommandHandler(IBaseRespository<StorageLocation> storageLocation)
        {
            _storageLocation = storageLocation;
        }

        public Task<ApiResult<List<StorageLocation>>> Handle(GetStorageLocationCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<List<StorageLocation>>()
            {
                Code = ApiEnum.Success,
                Msg = "仓库库区库位查询成功"
            };
            var liststorageLocation = _storageLocation.GetAll().Where(o => o.ZoneId == request.ZoneId);

            result.Data = liststorageLocation.ToList();

            return Task.FromResult(result);
        }
    }
}
